package vn.aptech.leaveManagementSystem.business;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimerTask;

import javax.swing.JOptionPane;


public class Validate {
	public boolean testAcceptDatesLeave(java.util.Date startDate,java.util.Date endDate, int leaveBalance)
	{
		Date today=new Date();
		if (startDate.compareTo(today)<=0)
		{
			JOptionPane.showMessageDialog(null, "StartDate must be after today. Please re-enter!");
			return false;
		}
		if (endDate.compareTo(startDate)>=0)
		{
			long s=endDate.getTime()-startDate.getTime();
			long days=(s/(1000*60*60*24))+1;
			System.out.println(days);
			if(days<=leaveBalance)
			{
				return true;
			}
			else
			{
				JOptionPane.showMessageDialog(null,
						"Number of days leave in your application:"+
						days+
						",\n"+
						"Leave balance:"+
						leaveBalance+
						".\n"+
						"Number of days leave cannot be greater than Leave Balance, please re-enter!");
				return false;
			}
		}
		else
		{
			JOptionPane.showMessageDialog(null, "EndDate must be equal to StartDate or EndDate must be after StartDate. Please re-enter!");
			return false;
		}
	}
}
